package com.studentportalen;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ScheduleArrayAdapter extends ArrayAdapter<Lecture> {

	private final Context context;
	private final List<Lecture> lectures;
	
	public ScheduleArrayAdapter(Context context, int resource, List<Lecture> objects) {
		super(context, resource, objects);
		
		this.context = context;
		lectures = objects;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		View rowView = inflater.inflate(R.layout.list_item_schedule, parent, false);
		
		TextView course = (TextView) rowView.findViewById(R.id.list_schedule_course);
		TextView info = (TextView) rowView.findViewById(R.id.list_schedule_info);
		
		course.setText(lectures.get(position).getCourse());
		String infoText = lectures.get(position).getStartDate() + " "
				+ lectures.get(position).getStartTime() + " - "
				+ lectures.get(position).getEndTime() + "; "
				+ lectures.get(position).getRoom();
		
		if(infoText.length() > 6)
			info.setText(infoText);

		return rowView;
	}
	
	@Override
	public boolean isEnabled(int position)	{
		return false;
	}

}
